import 'package:flutter_slidable_panel/controllers/slide_controller.dart';

class Device {
  int? masterUserId;
  String? masterUserName;
  String? robotUserId;

  int? powerValue;
  int? levelStatus;
  bool? isWifiOpen;
  int? wifiSingle;
  bool isWifiConnected = false;
  String? version;
  String? cloundVersion;
  String wifiName = '';

  //是否在线.
  bool isOnline = false;

  //是否为当前选中设备.
  bool selected = false;

  SlideController? slideController;

  Device() {}

  Device.fromJson(Map<String, dynamic> data) {
    if(data.containsKey('masterUserId'))
    masterUserId = data['masterUserId'];
    if(data.containsKey('masterUserName'))
    masterUserName = data['masterUserName'];
    if(data.containsKey('robotUserId'))
    robotUserId = data['robotUserId'];

    if(data.containsKey('powerValue'))
    powerValue = data['powerValue'];
    if(data.containsKey('levelStatus'))
    levelStatus = data['levelStatus'];
    if(data.containsKey('isWifiOpen'))
    isWifiOpen = data['isWifiOpen'];

    if(data.containsKey('wifiSingle'))
    wifiSingle = data['wifiSingle'];
    if(data.containsKey('isWifiConnected'))
    isWifiConnected = data['isWifiConnected'];
    if(data.containsKey('version'))
    version = data['version'];

    if(data.containsKey('cloundVersion'))
    cloundVersion = data['cloundVersion'];
    if(data.containsKey('isOnline'))
    isOnline = data['isOnline'];
    if(data.containsKey('selected'))
    selected = data['selected'];
    if(data.containsKey('wifiName'))
      wifiName = data['wifiName'];
      if (wifiName.length > 12) {
        wifiName = wifiName.substring(0,12) + '...';
      }

  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['masterUserId'] = this.masterUserId;
    data['masterUserName'] = this.masterUserName;
    data['robotUserId'] = this.robotUserId;

    data['powerValue'] = this.powerValue;
    data['levelStatus'] = this.levelStatus;
    data['isWifiOpen'] = this.isWifiOpen;

    data['wifiSingle'] = this.wifiSingle;
    data['isWifiConnected'] = this.isWifiConnected;
    data['version'] = this.version;

    data['cloundVersion'] = this.cloundVersion;
    data['isOnline'] = this.isOnline;
    data['selected'] = this.selected;
    data['wifiName'] = this.wifiName;

    return data;
  }

}

